import static letcode.tools.arrayout;

public class Test {
    public static String reverseWords(String s) {
        String trim = s.trim();
        String[] split = trim.split(" ");
        for (int i=0;i<split.length;i++)
        {
            System.out.println(split[i]);
        }
        System.out.println("\n");

        StringBuilder sb = new StringBuilder();
        for (int i=split.length-1;i>=0;i--)
        {
            if (i!=0)
            {
               /* if (split[i].equals("")) continue;*/
                sb.append(split[i]);
                sb.append(" ");
            }
            else {
                if (split[i].equals("")) continue;
                sb.append(split[i]);
            }
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        System.out.println(reverseWords("a good   example"));


    }

}

